package csel.model;

import java.util.EnumMap;
import java.util.Map;

public class VehicleStatHolder implements java.io.Serializable
{
	private static final long serialVersionUID = 5L;
	
	private EnumMap<VehicleStats, Integer> stats;
	private final EnumMap<DamageTypes, Integer> resistances;
	
	public VehicleStatHolder()
	{
		stats = new EnumMap<VehicleStats, Integer>(VehicleStats.class);
		resistances = new EnumMap<DamageTypes, Integer>(DamageTypes.class);
		
//		needed so that calculateDerived doesn't return null pointer exception since
		//setStat automatically calls calculateDerived
		stats.put(VehicleStats.MaxLife, 0);
		stats.put(VehicleStats.Damage, 0);
		//just in case??
		calculateDeriveds();
	}
	
	public int getResistance(DamageTypes dt)
	{
		Integer statval = resistances.get(dt);
		if(statval!=null)
		{
			return statval.intValue();
		}
		else
		{
			return(0);
		}
	}
	
	public int getStat(VehicleStats stat)
	{
		Integer statval = stats.get(stat);
		if(statval!= null)
		{
			return statval.intValue();
		}
		else
		{
			return(0);
		}
	}
	
	public Map<VehicleStats, Integer> getStats()
	{
		return stats.clone();
	}
	
	public void setStat(VehicleStats stat, int value)
	{
		stats.put(stat, value);
		calculateDeriveds();
	}
	
	public void setResistance(DamageTypes dt, int value)
	{
		resistances.put(dt, value);
	}

	private void calculateDeriveds()
	{
		int Life = stats.get(VehicleStats.MaxLife)
				- stats.get(VehicleStats.Damage);
		stats.put(VehicleStats.Life, Life);
	}
}
